package com.own.business.wallet.controller.manage;

import com.own.business.wallet.business.service.WalletHistoryService;
import com.own.business.wallet.entity.dto.WalletHistoryDto;
import com.own.business.wallet.entity.map.WalletHistoryMapVo;
import com.own.business.wallet.entity.query.WalletHistoryQuery;
import com.own.business.wallet.entity.vo.WalletHistoryVo;
import com.own.component.common.base.controller.BaseController;
import com.own.component.common.model.PageModel;
import com.own.component.common.model.R;
import com.own.component.common.model.ResultModel;
import com.own.constant.ConstantApiPrefix;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * ManageWalletHistoryController
 *
 * @author chenxueli
 * @date 2023-11-09 13:19:59
 */
@Tag(name = "钱包订单流水" + ConstantBeanSuffix.MANAGE_CLIENT + ConstantBeanSuffix.CONTROLLER)
@RestController
@RequestMapping(ConstantApiPrefix.BASE_API_V1_PREFIX + ConstantApiPrefix.MANAGE_CLIENT + "wallet/history")
public class ManageWalletHistoryController extends BaseController {

    @Resource
    private WalletHistoryService walletHistoryService;

    @Operation(summary = "查询所有信息")
    @PostMapping("/all")
    public ResultModel<List<WalletHistoryVo>> all(
            @RequestBody WalletHistoryQuery query
    ) {
        var pageModel = walletHistoryService.all(query);
        return R.success(pageModel);
    }

    @Operation(summary = "分页查询信息")
    @PostMapping("/page")
    public ResultModel<PageModel<WalletHistoryVo>> page(
            @RequestBody WalletHistoryQuery query
    ) {
        var pageModel = walletHistoryService.page(query);
        return R.success(pageModel);
    }

    @Operation(summary = "map查询信息")
    @PostMapping("/map")
    public ResultModel<List<WalletHistoryMapVo>> map(
            @RequestBody WalletHistoryQuery query
    ) {
        var list = walletHistoryService.map(query);
        return R.success(list);
    }

    @Operation(summary = "添加信息")
    @PostMapping("/")
    public ResultModel<WalletHistoryVo> add(
            @Validated @RequestBody WalletHistoryDto dto
    ) {
        dto.check();
        var updateModel = walletHistoryService.add(dto.toBo());
        return R.success(updateModel);
    }

    @Operation(summary = "修改信息")
    @PutMapping("/{walletHistoryId}")
    public ResultModel<WalletHistoryVo> update(
            @Parameter(description = "主键id", required = true) @PathVariable Long walletHistoryId,
            @Validated @RequestBody WalletHistoryDto dto
    ) {
        dto.check();
        var updateModel = walletHistoryService.update(walletHistoryId, dto.toBo());
        return R.success(updateModel);
    }

    @Operation(summary = "删除信息")
    @DeleteMapping("/{walletHistoryId}")
    public ResultModel<Boolean> delete(
            @Parameter(description = "主键id", required = true) @PathVariable Long walletHistoryId
    ) {
        var updateModel = walletHistoryService.delete(walletHistoryId);
        return R.success(updateModel);
    }

    @Operation(summary = "根据id获取信息")
    @GetMapping("/{walletHistoryId}")
    public ResultModel<WalletHistoryVo> getById(
            @Parameter(description = "主键id", required = true) @PathVariable Long walletHistoryId
    ) {
        var vo = walletHistoryService.getById(walletHistoryId);
        return R.success(vo);
    }

}
